# -*- coding: utf-8 -*-
from sklearn import datasets, model_selection
from sklearn.metrics import classification_report
from sklearn import svm
import numpy as np

iris = datasets.load_iris() 
x = iris['data']
y = iris['target']

x_train, x_test, y_train, y_test = model_selection.train_test_split(x, y)

#线性核
clf_linear = svm.SVC(C=0.9, decision_function_shape="ovo", kernel="linear")
#高斯核
clf_rbf = svm.SVC(C=0.9, decision_function_shape="ovo", kernel="rbf")

#fit
clf_linear.fit(x_train, y_train)
clf_rbf.fit(x_train, y_train)

#测试集正确率
y_test_pre_linear = clf_linear.predict(x_test)
y_test_pre_rbf = clf_rbf.predict(x_test)

print("======== 高斯核 =========")
print(classification_report(y_test, y_test_pre_rbf, target_names=iris['target_names']))
print("======== 线性核 =========")
print(classification_report(y_test, y_test_pre_linear, target_names=iris['target_names']))